package com.jh3502.helper.function.batch.mytask;
import android.support.annotation.NonNull;

import com.jh3502.helper.base.BaseCallback;
import com.jh3502.helper.base.BaseJson;
import com.jh3502.helper.base.BasePresenter;
import com.jh3502.helper.base.BaseView;
import com.jh3502.helper.function.batch.mytask.MyTaskModel;
import com.jh3502.helper.utils.Utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author harisucici
 * @date 2017/6/19
 */

public class MyTaskPresenter extends BasePresenter {
    MyTaskModel mMyTaskModel;

    MyTaskView mMyTaskView;

    public void setMyTaskView(MyTaskView mMyTaskView) {
        this.mMyTaskView = mMyTaskView;
    }

    //  保存数据
    public void toSaveoneall(Map<String, Object> body) {
        mMyTaskView.showLoadingDialog();
        if (mMyTaskModel == null) {
            mMyTaskModel = new MyTaskModel(mMyTaskView.getActContext());
        }

        mMyTaskModel.saveoneall(body, new BaseCallback(mMyTaskView) {
            @Override
            public void responseSuccess(BaseJson baseJson) {
                mMyTaskView.saveoneallSuccess();
            }


        });
    }

    //  量体任务列表
    public void toListall(String username) {
        mMyTaskView.showLoadingDialog();
        if (mMyTaskModel == null) {
            mMyTaskModel = new MyTaskModel(mMyTaskView.getActContext());
        }

        mMyTaskModel.listall(username, new BaseCallback(mMyTaskView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                Map<String, Object> map = Utils.getInstance().jso2map(baseJson.getObj().toString());
                mMyTaskView.listallSuccess((String) map.get("rows"));
            }
        });
    }

    //  人员
    public void toGetoneall(String batno) {
        mMyTaskView.showLoadingDialog();
        if (mMyTaskModel == null) {
            mMyTaskModel = new MyTaskModel(mMyTaskView.getActContext());
        }

        mMyTaskModel.getoneall(batno, new BaseCallback(mMyTaskView) {
            @Override
            public void responseSuccess(@NonNull BaseJson baseJson) {
                Map<String, Object> map = new HashMap<>(2);
                map.put("batno", batno);
//                ArrayList<PersonListBean> arrayList = new Gson().fromJson(, new TypeToken<List<PersonListBean>>() {}.getType());
                map.put("datalist", Utils.getInstance().jso2map(baseJson.getObj().toString()).get("ltBatPersonDOLst"));
//
//                ArrayList<PersonListBean> personList = new ArrayList<>();
//                if (personListTemp != null) {
//                    for (PersonListBean personListBean : personListTemp) {
//                        personListBean.setOnline(Constant.ONLINE);
//                        personList.add(personListBean);
//                    }
//                }
//                SpHelper.getInstance().setPersonList((String) batch.get("batno"), personList);
                mMyTaskView.getoneallSuccess(map);
            }
        });
    }

    @Override
    public void cancelCall() {

    }

    public interface MyTaskView extends BaseView {
        void getoneallSuccess(Map<String, Object> map);

        void saveoneallSuccess();

        void listallSuccess(String rows);
    }
}
